package com.yoomiito.app.ui.my.songdudouo

import android.net.Uri
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.Constant
import com.yoomiito.app.R
import com.yoomiito.app.base.App
import com.yoomiito.app.model.my.GiveMoreIncomeDetail
import com.yoomiito.app.utils.ImageLoader
import com.yoomiito.app.widget.CircleImageView

class GiveMoreIncomeAdapter(data:List<GiveMoreIncomeDetail>?,var type:Int=Constant.NAMAL_TYPE_INCOME_FREE_GIFT) :BaseQuickAdapter<GiveMoreIncomeDetail,BaseViewHolder>(R.layout.item_my_order,data){

    override fun convert(helper: BaseViewHolder?, item: GiveMoreIncomeDetail?) {
        helper?.setGone(R.id.tipIv,Constant.NAMAL_TYPE_INCOME_FREE_GIFT==type)
        helper?.addOnClickListener(R.id.tipIv)
        helper?.setText(R.id.tv_order_num,"订单：${item?.sn}")
        helper?.setGone(R.id.iv_st,false)
        val userImg = helper?.getView<CircleImageView>(R.id.iv_photo)
        val requestOptions = RequestOptions()
        requestOptions.placeholder(R.drawable.goods_default)
        if (!item?.headimgurl.isNullOrEmpty()) {
            Glide.with(App.getApplication()).load(Uri.parse(item?.headimgurl)).apply(requestOptions).into(userImg!!)
        }
        helper?.setText(R.id.tv_name,item?.nickname)
        val flagIv1 = helper?.getView<ImageView>(R.id.iv_st)
        if (TextUtils.isEmpty(item?.image_url)) {
            flagIv1?.visibility = View.GONE
        } else {
            flagIv1?.visibility = View.VISIBLE
            ImageLoader.getInstance().into(flagIv1?.context, item?.image_url, flagIv1)
        }
        val goodsDetailTv = helper?.getView<TextView>(R.id.item_order_goods_name)
        goodsDetailTv?.text = item?.product_name
        goodsDetailTv?.visibility = View.VISIBLE
        helper?.setText(R.id.tv_date,item?.ctime)
        helper?.setText(R.id.tv_money,item?.user_income)
        val statusIv = helper?.getView<ImageView>(R.id.iv_status)
        when(item?.status){
            Constant.ORDER_STATUS_WAIT_PAY->{
                statusIv?.visibility= View.GONE
            }
            Constant.ORDER_STATUS_PAYED->{
                statusIv?.visibility= View.VISIBLE
                statusIv?.setImageResource(R.mipmap.already_settled)
            }
            else->{
                statusIv?.visibility= View.GONE
            }
        }
        helper?.setGone(R.id.submitTv,Constant.NAMAL_TYPE_INCOME_FREE_GIFT==type&&item?.status==Constant.ORDER_STATUS_WAIT_PAY)
        helper?.addOnClickListener(R.id.submitTv)
    }

}